package main

import (
	user "../day26/entity"
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"time"
)

func main() {

	const DB_TYPE = "mysql"
	const DB_URL = "root:root@/go?charset=utf8&parseTime=True&loc=Local"
	con, err := gorm.Open(DB_TYPE, DB_URL)
	if err != nil {
		fmt.Println(err)
		return
	}

	defer con.Close()

	// 自动迁移模式
	con.AutoMigrate(&user.User{})
	user := user.User{Name: "MARK", Age: 18, Birthday: time.Now()}
	//
	fmt.Println(con.NewRecord(user)) // => returns `true` as primary key is blank
	//
	con.Create(&user)
	//
	fmt.Println(con.NewRecord(user)) // => return `false` after `user` created、

}
